package com.cskaoyan.service.impl;

import com.cskaoyan.bean.MarketLog;
import com.cskaoyan.bean.MarketLogExample;
import com.cskaoyan.bean.zhangshizhi.web.log.LogBO;
import com.cskaoyan.bean.zhangshizhi.web.log.LogVO;
import com.cskaoyan.mapper.MarketLogMapper;
import com.cskaoyan.service.LogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @author little ants（张时智）
 * @since 2022/06/25 17:20
 */

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    MarketLogMapper mapper;


    @Override
    public LogVO getLogList(LogBO pageBO) {

        PageHelper.startPage(pageBO.getPage(), pageBO.getLimit());
        MarketLogExample marketLogExample = new MarketLogExample();
        marketLogExample.setOrderByClause(pageBO.getSort() + " " + pageBO.getOrder());
        MarketLogExample.Criteria criteria = marketLogExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (pageBO.getName() != null && !Objects.equals(pageBO.getName(), "")) {
            criteria.andAdminLike("%" + pageBO.getName() + "%");
        }

        List<MarketLog> marketLogs = mapper.selectByExample(marketLogExample);

        LogVO logVO = new LogVO();

        logVO.setList(marketLogs);
        logVO.setLimit(pageBO.getLimit());
        logVO.setPage(pageBO.getPage());

        PageInfo<MarketLog> marketLogPageInfo = new PageInfo<>(marketLogs);

        logVO.setTotal((int) marketLogPageInfo.getTotal());
        logVO.setPages(marketLogPageInfo.getPages());


        return logVO;
    }
}
